package com.zlsy.secondtime.threadcoreknowledge.stopthreads;

/**
 * @author zhouliang
 * @date 2020/5/15 9:55
 * <p>
 * run方法内有sleep或则wait方法时候，停止线程
 */
public class RightWayStopThreadWithSleep implements Runnable {

    @Override
    public void run() {
        int num = 0;
        while (num < 3000) {
            if (num % 100 == 0) {
                System.out.println("当前num: " + num);
            }
            num++;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        RightWayStopThreadWithSleep r = new RightWayStopThreadWithSleep();
        Thread thread = new Thread(r);
        thread.start();
        Thread.sleep(500);
        thread.interrupt();
    }
}
